package com.zork.cmdb.webapi.api;

import com.zork.cmdb.webapi.common.response.ResponseEntityEnum;
import com.zork.cmdb.webapi.domain.vo.UserVO;
import com.zork.cmdb.webapi.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chenjh
 * @date 2018/5/9
 * @description
 */
@RestController
@RequestMapping(value="/users")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value="获取所有用户列表", notes="获取所有用户列表")
    @GetMapping("")
    public ResponseEntityEnum listUser() {
        List<UserVO> userList = userService.listUser();
        ResponseEntityEnum result = ResponseEntityEnum.SUCCESS.setData(userList);
        return result;
    }

    @ApiOperation(value="获取单个用户信息", notes="获取单个用户信息")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public ResponseEntityEnum getUser(@PathVariable Long id) {
        UserVO userVO = userService.getUser(id);
        ResponseEntityEnum result = ResponseEntityEnum.SUCCESS.setData(userVO);
        return result;
    }
}
